const notLogin = [
  "/pages/login/login",
  "/pages/my/my",
  "/pages/rich_text/rich_text",
  "/pages/index/index",
  "/pages/cake/cake",
  "/pages/archive/archive",
  "/pages_goods/goods_detail/goods_detail",
];


let list = ["navigateTo", "redirectTo", "reLaunch", "switchTab"];
list.forEach(item => { 
  uni.addInterceptor(item, {
    invoke(e) { // 调用前拦截
	
	if(e.url != '/pages/login/login') {
		uni.setStorageSync('target_url',e.url) // 存储目标页面的url用于登陆回显
	}
      const token = uni.getStorageSync('token')
      //获取当前页面路径（即url去掉"?"和"?"后的参数）
      const url = e.url.split('?')[0]
      console.log(url, '|-调用前拦截,router index url')
      if (!notLogin.includes(url) && token == '') {
        uni.showToast({
          title: '请登陆后访问哦～',
          icon: 'none',
		  success() {
		  	setTimeout(() => {
				uni.navigateTo({
				  url: "/pages/login/login"
				})
			},1000)
		  }
        })
        return false
      }
 
      return true
    },
    fail(err) { // 失败回调拦截
      console.log(err);
    },
  })
})